package com.mkj.basic;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

/**
 * @Author Arrebol
 * @Date 2024/8/6 16:34
 * @Project graphical programming
 * @Description：
 * 颜色选择器组件基本演示
 */
public class JColorChooserDemo {

    private final JFrame frame=new JFrame("测试颜色选择器");
    private JTextArea textArea = new JTextArea("啊哈哈哈哈",6,30);
    //声明按钮
    JButton button = new JButton(new AbstractAction("改变文本框背景颜色") {
        @Override
        public void actionPerformed(ActionEvent e) {
            //弹出一个颜色选择器，选择了颜色，要修改文本域背景
            Color result = JColorChooser.showDialog(frame, "颜色选择器", Color.WHITE);
            //修改文本域背景
            textArea.setBackground(result);
        }
    });
    public void init(){
        //组装视图
        frame.add(textArea);
        frame.add(button,BorderLayout.SOUTH);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new JColorChooserDemo().init();
    }
}
